//
//  DDRightToLeftTextField.m
//  DongDongWeddingBusiness
//
//  Created by 谢曦 on 2016/10/31.
//  Copyright © 2016年 gl. All rights reserved.
//

#import "RightToLeftTextField.h"
#import "Masonry.h"
#define kmargin 2
@interface RightToLeftTextField ()
{
     CGSize textSize;
}
@end
@implementation RightToLeftTextField
-(instancetype)init
{
    if (self=[super init]) {
//        self.delegate=self;
        _maxStrLength=NSUIntegerMax;
        self.tintColor=ThemeGreenColor;
        self.textAlignment=NSTextAlignmentRight;
        
          }
    return self;
}
////控制placeHolder的位置
//-(CGRect)placeholderRectForBounds:(CGRect)bounds
//{
//#pragma clang diagnostic push
//#pragma clang diagnostic ignored"-Wdeprecated-declarations"
//    CGSize size= [self.placeholder sizeWithFont:self.font];
//    #pragma clang diagnostic pop
//    CGRect inset = CGRectMake(bounds.size.width-kmargin-size.width, bounds.origin.y, bounds.size.width -10, bounds.size.height);//更好理解些
//    return inset;
//}
//
////控制显示文本的位置
//-(CGRect)textRectForBounds:(CGRect)bounds
//{
////  CGSize size= [self.text sizeWithFont:self.font];
////
////    CGRect inset = CGRectMake(bounds.size.width-kmargin-size.width, bounds.origin.y, bounds.size.width-90 , bounds.size.height);
////    if (inset.origin.x<=0) {
////        return CGRectMake(0, bounds.origin.y, bounds.size.width , bounds.size.height);
////    }
////   else return inset;
//#pragma clang diagnostic push
//#pragma clang diagnostic ignored"-Wdeprecated-declarations"
//    CGSize size= [self.text sizeWithFont:self.font];
//    #pragma clang diagnostic pop
//    CGRect inset = CGRectMake(self.frame.size.width-kmargin-size.width, bounds.origin.y, size.width +kmargin, bounds.size.height);
//    if (size.width>=bounds.size.width) {
//        return CGRectMake(0, bounds.origin.y, bounds.size.width, bounds.size.height);
//    }
//    
//   
//    
//    return inset;
//}
//
////控制文本的位置起始
////编辑文本的时候就会调用
////切换输入法也会调用
//-(CGRect)editingRectForBounds:(CGRect)bounds
//{
//#pragma clang diagnostic push
//#pragma clang diagnostic ignored"-Wdeprecated-declarations"
//      CGSize size= [self.text sizeWithFont:self.font];
//    #pragma clang diagnostic pop
//         CGRect inset = CGRectMake(bounds.size.width-kmargin-size.width, bounds.origin.y, size.width+kmargin , bounds.size.height);
//    if (size.width>=bounds.size.width) {
//        return CGRectMake(0, bounds.origin.y, bounds.size.width, bounds.size.height);
//    }
//    if (self.text.length>0) {
//        [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            
//            
//            if ([NSStringFromClass([obj class]) hasPrefix:@"UIFieldEditor"]) {
//                if ([NSStringFromClass([[obj.subviews firstObject] class]) hasPrefix:@"_UIFieldEditorContentView"]) {
//                    //obj UIFieldEditor
//                    UIView *editor=[obj.subviews firstObject];//_UIFieldEditorContentView
//                    if (_useClearWord==YES) {
//                        //解决第三方输入法清除时候的问题
//                        [obj mas_updateConstraints:^(MASConstraintMaker *make) {
//                            make.width.mas_equalTo(size.width);
//                        }];
//                    }
//                        
//                    else{
//                        //解决自带输入法中文输入错位的问题
//                        [obj mas_updateConstraints:^(MASConstraintMaker *make) {
//                        make.width.mas_equalTo(editor.bounds.size.width);
//                    }];
//                    
//                    [self layoutIfNeeded];
//                    }
//                    
//                }
//                
//            }
//            
//            
//            
//        }];
//    }
//
//
//    
//    
//    return inset;
//
//}
//
//-(void)layoutSubviews
//{
//    [super layoutSubviews];
//    
//    
//}
//设置占位字符
-(void)setPlaceholder:(NSString *)placeholder
{
    if (placeholder==nil||placeholder.length==0) {
        super.placeholder = placeholder;
        return;
    }
//    if (![[placeholder substringToIndex:1] isEqualToString:@"*"]) {
//        super.placeholder = placeholder;
//        return;
//    }
    NSMutableAttributedString *placeholderAtt = [[NSMutableAttributedString alloc]initWithString:placeholder];
//    [placeholderAtt addAttribute:NSForegroundColorAttributeName
//                        value:[UIColor redColor]
//                        range:NSMakeRange(0,1)];
    [placeholderAtt addAttribute:NSForegroundColorAttributeName
                           value:[UIColor whiteColor]
                           range:NSMakeRange(0,placeholder.length)];
    self.attributedPlaceholder = placeholderAtt;



}

@end
